<template>
  <div class="app-container">
    <div class="box-form-top"></div>
    <div class="box-form">
      <div class="container">
        <div id="echart"></div>
      </div>
    </div>
    <div class="box-form-bottom"></div>
  </div>
  <!-- <div>
    <div class="container">
        <div id="echart"></div>
    </div>
  </div> -->
</template>
    
          <script>
import * as api from "./api";
import * as echarts from "echarts";
export default {
  name: "defectCounts",
  components: {},
  data() {
    return {};
  },
  watch: {},
  methods: {
    test() {
      var myChart = this.$echarts.init(document.getElementById("main"));
      var colorList = ["#4FE894", "#EF0C27", "#FEE7EA"];
      var listData = [
        { name: "不明", value: 20 },
        { name: "已判明", value: 20 },
        { name: "未发现", value: 20 },
      ];
      var option = {
        color: colorList,
        title: {
          x: "center",
          y: "center",
          textStyle: {
            color: "#000",
            fontSize: 20,
          },
        },
        legend: {
          orient: "vertical",
          bottom: 5,
          align: "right",
          right: 15,
          textStyle: {
            color: "#000",
            fontSize: 20,
          },
          selectedMode: false,
          data: ["元素1", "元素2", "元素3"],
        },
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            type: "pie",
            center: ["50%", "50%"],
            radius: ["55%", "35%"],
            itemStyle: {
              normal: {
                color: function (params) {
                  return colorList[params.dataIndex];
                },
              },
            },
            label: {
              show: true,
              fontSize: 10,
              color: "#000",
              formatter: function (data) {
                return data.name + ":" + data.percent.toFixed(0) + "%";
              },
            },
            labelLine: {
              normal: {
                length: 15,
                length2: 15,
                lineStyle: {
                  width: 2,
                },
              },
            },
            data: listData,
          },
        ],
      };
      myChart.setOption(option);
    },
    getLoadEcharts() {
      var myChart = this.$echarts.init(document.getElementById("echart"));
      var colorList = ["#4FE894", "#EF0C27", "#FEE7EA"];
      var listData = [
        { name: "不明", value: 20 },
        { name: "已判明", value: 20 },
        { name: "未发现", value: 20 },
      ];
      var option = {
        color: colorList,
        title: {
          x: "center",
          y: "center",
          textStyle: {
            color: "#000",
            fontSize: 20,
          },
        },
        legend: {
          orient: "vertical",
          bottom: 5,
          align: "right",
          right: 15,
          textStyle: {
            color: "#000",
            fontSize: 20,
          },
          selectedMode: false,
          data: ["元素1", "元素2", "元素3"],
        },
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            type: "pie",
            center: ["50%", "50%"],
            radius: ["55%", "35%"],
            itemStyle: {
              normal: {
                color: function (params) {
                  return colorList[params.dataIndex];
                },
              },
            },
            label: {
              show: true,
              fontSize: 10,
              color: "#000",
              formatter: function (data) {
                return data.name + ":" + data.percent.toFixed(0) + "%";
              },
            },
            labelLine: {
              normal: {
                length: 15,
                length2: 15,
                lineStyle: {
                  width: 2,
                },
              },
            },
            data: listData,
          },
        ],
      };
      myChart.setOption(option);
    },
  },
  mounted() {
    this.getLoadEcharts();
  },
};
</script>
    
          <style scoped lang="scss">
.container {
  width: 300px;
  height: 300px;
  margin-left: 30px;
}
#echart {
  width: 100%;
  height: 100%;
}
.app-container {
  //padding: 20px;
  min-height: 250px;
  padding: 20px 20px 0px 20px;
  margin-right: auto;
  margin-left: auto;
}
.box-form-top {
  text-align: center;
  line-height: 100%;
  align-items: center;
  position: relative;
  border-top: 0;
  margin-bottom: 15px;
  width: 100%;
  background: #fff;
  border-radius: 0;
  padding: 10px;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-direction: column;
  flex-direction: column;
  border: 1px solid #dce3e6;
  border-radius: 4px;
  -webkit-box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
  box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
}
.box-form {
  height: 70vh;
  position: relative;
  border-top: 0;
  margin-bottom: 15px;
  width: 100%;
  background: #fff;
  border-radius: 0;
  padding: 10px;
  display: flex;
  border: 1px solid #dce3e6;
  border-radius: 4px;
  -webkit-box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
  box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
  overflow: auto;

  .form_content {
    .form_content_detail {
      padding: 10px;
      background: #eee;
    }
  }
}

.box-form-bottom {
  position: relative;
  border-top: 0;
  margin-bottom: 15px;
  width: 100%;
  background: #fff;
  border-radius: 0;
  padding: 10px;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-direction: column;
  flex-direction: column;
  border: 1px solid #dce3e6;
  border-radius: 4px;
  -webkit-box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
  box-shadow: 0px 5px 20px rgba(0, 0, 0, 0.05);
}
</style>
    